package top.infopub.mgr.mkt.service.impl;

import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.infopub.dto.mkt.RiskOverviewDto;
import top.infopub.enums.mkt.StandardEnum;
import top.infopub.mgr.mkt.dao.ProjectSubInfoDao;
import top.infopub.mgr.mkt.dao.RiskOverviewDtoDao;
import top.infopub.mgr.mkt.service.ProProcessManageService;
import top.infopub.mgr.mkt.service.RiskOverviewDtoService;
import top.infopub.mgr.mkt.vo.InvestmentInfoVo;
import top.infopub.model.mkt.ProjectInfo;
import top.infopub.model.mkt.ProjectRisk;
import top.infopub.model.mkt.ProjectSubInfo;

import java.math.BigDecimal;
import java.util.List;

@Service
public class RiskOverviewDtoServiceImpl implements RiskOverviewDtoService {

    @Autowired
    private RiskOverviewDtoDao riskOverviewDtoDao;

    @Autowired
    private ProjectSubInfoDao projectSubInfoDao;
    @Autowired
    private ProProcessManageService proProcessManageService;
    @Override
    public RiskOverviewDto queryDetail(String id) {
        RiskOverviewDto dto=new RiskOverviewDto();
        ProjectRisk projectRisk = riskOverviewDtoDao.selectProRiskById(id);
        ProjectInfo projectInfo = riskOverviewDtoDao.selectProInfoByProCode(projectRisk.getProCode());
        ProjectSubInfo projectSubInfo = projectSubInfoDao.queryByProCode(projectInfo.getProCode());
        List<InvestmentInfoVo> investmentInfoVos = JSON.parseArray(projectSubInfo.getContentJson(), InvestmentInfoVo.class);
        BigDecimal rowSum = BigDecimal.ZERO;
        for (InvestmentInfoVo investmentInfoVo : investmentInfoVos) {
            if (StandardEnum.GET_JIANAN.getBaseLineName().equals(investmentInfoVo.getName())
            ){
                rowSum = investmentInfoVo.getTotal();
            }
        }
        dto.setProjectInfo(projectInfo);
        dto.setProjectRisk(projectRisk);
        dto.setRowSum(rowSum);//建安工程费用
        String typeName = proProcessManageService.queryProProcessType(projectRisk.getProCode()).getTypeName();
        dto.setTypeName(typeName);
        return dto;
    }
}
